package com.weme.common.dialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.ViewModelProvider
import com.jeremyliao.liveeventbus.LiveEventBus
import com.weme.common.R
import com.weme.common.base.BaseDialog
import com.weme.common.util.LiveConfig.NET_USER_INFO_AROUTER
import com.weme.common.viewmodel.ToUserInfoViewModel
import dev.kratos.api.user_server.v1.CheckBlackRequest
import java.lang.Deprecated

@Deprecated
class IsBlackInfoDialog(var callback: (Boolean) -> Unit) : BaseDialog() {

    private var userId: String = ""

    companion object {
        private const val ARG_USER_ID = "user_id"

        fun show(fragmentManager: FragmentManager, userId: String,callback: (Boolean) -> Unit) {
            val dialog = IsBlackInfoDialog(callback).apply {
                arguments = Bundle().apply {
                    putString(ARG_USER_ID, userId)
                }
            }
            dialog.show(fragmentManager, IsBlackInfoDialog::class.java.simpleName)
        }
    }

    override fun onStart() {
        super.onStart()
        dialog?.window?.apply {
            attributes.windowAnimations = 0
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        arguments?.let {
            userId = it.getString(ARG_USER_ID).toString()
        }
    }
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.dialog_to_userinfo, container, false)
        val viewModel = ViewModelProvider(this)[ToUserInfoViewModel::class.java]
        viewModel.isCheckBlack(CheckBlackRequest.newBuilder().setUid(userId.toLong()).build())
     LiveEventBus.get<Any>(NET_USER_INFO_AROUTER).observe(this) {
//            if (it is IsBlack) {
//                callback.invoke(!it.isBlack)
//                dismiss()
//            }
        }
        return view
    }
}